%%
%% HTTP status codes
%%
%% 1xx: Informational
-define(CONTINUE,     {100, "Continue"}).
-define(SWITCH_PROTO, {101, "Switching Protocols"}).

%% 2xx: Success
-define(OK,                {200, "OK"}).
-define(CREATED,           {201, "Created"}).
-define(ACCEPTED,          {202, "Accepted"}).
-define(NON_AUTHORITATIVE, {203, "Non-Authoritative Information"}).
-define(NO_CONTENT,        {204, "No Content"}).
-define(RESET,             {205, "Reset Content"}).
-define(PARTIAL,           {206, "Partial Content"}).

%% 3xx: Redirection
-define(MULTIPLE_CHOICES, {300, "Multiple Choices"}).
-define(MOVED,            {301, "Moved Permanently"}).
-define(FOUND,            {302, "Found"}).
-define(SEE_OTHER,        {303, "See Other"}).
-define(REDIRECT,         {303, "See Other"}). % alias for see_other
-define(NOT_MODIFIED,     {304, "Not Modified"}).
-define(USE_PROXY,        {305, "Use Proxy"}).
-define(TEMPORARY,        {307, "Temporary Redirect"}).

%% 4xx: Client Error
-define(BAD_REQ,                   {400, "Bad Request"}).
-define(UNAUTH,                    {401, "Unauthorized"}).
-define(PAYMENT_REQUIRED,          {402, "Payment Required"}).
-define(FORBIDDEN,                 {403, "Forbidden"}).
-define(NOT_FOUND,                 {404, "Not Found"}).
-define(METHOD_NOT_ALLOWED,        {405, "Method Not Allowed"}).
-define(NOT_ACCEPTABLE,            {406, "Not Acceptable"}).
-define(PROXY_AUTH_REQUIRED,       {407, "Proxy Authentication Required"}).
-define(REQ_TIMEOUT,               {408, "Request Time-out"}).
-define(CONFLICT,                  {409, "Conflict"}).
-define(GONE,                      {410, "Gone"}).
-define(LENGTH_REQUIRED,           {411, "Length Required"}).
-define(PRECONDITION_FAILED,       {412, "Precondition Failed"}).
-define(REQ_ENTITY_TOO_LARGE,      {413, "Request Entity Too Large"}).
-define(REQ_URI_TOO_LARGE,         {414, "Request-URI Too Large"}).
-define(UNSUPPORTED_MEDIA_TYPE,    {415, "Unsupported Media Type"}).
-define(REQ_RANGE_NOT_SATISFIABLE, {416, "Requested range not satisfiable"}).
-define(EXPECTATION_FAILED,        {417, "Expectation Failed"}).

%% 5xx: Server Error
-define(INTERNAL_SERVER_ERROR,      {500, "Internal Server Error"}).
-define(ERROR,                      {500, "Internal Server Error"}). % alias for internal_server_error
-define(NOT_IMPLEMENTED,            {501, "Not Implemented"}).
-define(BAD_GW,                     {502, "Bad Gateway"}).
-define(SERVICE_UNAVAILABLE,        {503, "Service Unavailable"}).
-define(GW_TIMEOUT,                 {504, "Gateway Time-out"}).
-define(HTTP_VERSION_NOT_SUPPORTED, {505, "HTTP Version not supported"}).


-define(status_msg(Status), lists:flatten([integer_to_list(element(1, Status)), " ", element(2, Msg)])).
               
%% extract method from request
-define(ewgi_get_data(Env), case ewgi_api:method(Env) of
                           'POST' -> ewgi_api:parse_post(ewgi_api:get_value(content_body, Env));
                           'GET'  -> ewgi_api:parse_qs(ewgi_api:qs(Env))
                       end
       ).

-define(DEFAULT_CHUNKSIZE, 4096).
-define(COMMA_SEPARATED_HEADERS, ["ACCEPT", "ACCEPT-CHARSET", "ACCEPT-ENCODING",
                                  "ACCEPT-LANGUAGE", "ACCEPT-RANGES", "ALLOW", "CACHE-CONTROL",
                                  "CONNECTION", "CONTENT-ENCODING", "CONTENT-LANGUAGE", "EXPECT",
                                  "IF-MATCH", "IF-NONE-MATCH", "PRAGMA", "PROXY-AUTHENTICATE", "TE",
                                  "TRAILER", "TRANSFER-ENCODING", "UPGRADE", "VARY", "VIA", "WARNING",
                                  "WWW-AUTHENTICATE"]).

-define(EWGI_ENV_DATA, [{server_sw, "SERVER_SOFTWARE"},
                        {server_name, "SERVER_NAME"},
                        {gw_interface, "GATEWAY_INTERFACE"},
                        {server_protocol, "SERVER_PROTOCOL"},
                        {server_port, "SERVER_PORT"},
                        {method, "REQUEST_METHOD"},
                        {path_info, "PATH_INFO"},
                        {path_translated, "PATH_TRANSLATED"},
                        {script_name, "SCRIPT_NAME"},
                        {qs, "QUERY_STRING"},
                        {content_type, "CONTENT_TYPE"},
                        {content_length, "CONTENT_LENGTH"},
                        {remote_host, "REMOTE_HOST"},
                        {remote_addr, "REMOTE_ADDR"},
                        {read_input, "ewgi.read_input"},
                        {write_error, "ewgi.write_error"},
                        {ewgi_version, "ewgi.version"},
                        {url_scheme, "ewgi.url_scheme"},
                        {ewgi_data, "ewgi.data"}]).
